package cn.kgc.springboot03.controller;

import cn.kgc.springboot03.entity.User;
import cn.kgc.springboot03.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Author: 课工场
 * @Version: v1.0  2023/3/22
 * @Description:
 */
@Controller
@RequestMapping("user")
@Slf4j  // lombok
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("list")
    @ResponseBody
    public List<User> getList(){
        List<User> list = userService.getList();
        return  list ;
    }

    @GetMapping("page")
    @ResponseBody
    public List<User> getPage(Integer page,Integer limit){
        List<User> list = userService.getPage(page,limit);
        return  list ;
    }

    @GetMapping("jsp")
    public String showList(Model model){
        List<User> list = userService.getList();
        model.addAttribute("users", list);
        /*
        *   通过日志的形式实现信息的输出  通过调整日志的级别实现灵活的控制信息是否打印
        *   TRACE  DEBUG < INFO < WARN < ERROR  FATAL
        *
        * */
        for (User user : list) {
            // 使用{} 实现数据的占位
            log.debug("id={},uname={}",user.getId(),user.getUname());
        }
        return  "user";
    }


}
